import type { IObj } from '@/interface'

// Message
interface IMsgOptions extends IObj {
    msg: string,
    // 提示时间 默认~1500~
    duration?: number,
    // 提示图标
    icon?: 'success' | 'error',
    // 自定义图标
    image?: string,
    // 禁止触摸穿透 默认~false~
    mask?: boolean,
}
export const Msg = (options: IMsgOptions) => {
    if (options?.icon && options.msg.length > 7) return new Error('Msg方法使用icon属性时，msg字数上限: 7')
    return uni.showToast({ icon: 'none', ...(options as IObj), title: options.msg, duration: options.duration ?? 2000 })
}

// Msg Loading
export const MsgLoading = (msg?: string, mask = true) => uni.showLoading({
    title: msg ?? '加载中',
    mask,
})
export const MsgLoadingClear = (options?: IMsgOptions) => {
    setTimeout(() => {
        uni.hideLoading()
    }, 2000)
    if (options) {
        Msg(options)
    }
}
export const PMsgLoadingClean = (options?: IMsgOptions) => {
    uni.hideLoading()
    if (options) {
        Msg(options)
    }
}
